/// ImageManager.java
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;

public class ImageManager {
    private static Map<String, BufferedImage> images = new HashMap<>();

    public static BufferedImage getImage(String imageName) {
        if (images.containsKey(imageName)) {
            return images.get(imageName);
        }

        try {
            // 使用类加载器加载资源
            var resource = ImageManager.class.getClassLoader().getResource("images/" + imageName);
            if (resource == null) {
                System.err.println("Image not found: " + imageName);
                return null;
            }

            BufferedImage image = ImageIO.read(resource);
            images.put(imageName, image);
            System.out.println("Image loaded successfully: " + imageName);
            return image;
        } catch (IOException e) {
            System.err.println("Error loading image: " + imageName);
            e.printStackTrace();
            return null;
        }
    }
}